<template>
	<view>
		<view class="item" v-for="(item, index) in list" :key="index" @click="golitian(item)">
			<view class="img" v-if="item.userProfile.avatar">
				<u-badge class="tip" max="99" :count="item.unreadCount"></u-badge>
				<image :src="item.userProfile.avatar" mode=""></image>
			</view>
			<view class="items_cont">
				<view class="items_top">
					<view class="items_name">{{ item.userProfile.nick }}</view>
					<view v-if="item.lastMessage" class="items_time">{{ item.lastMessage.lastTime | dateFormat }}</view>
				</view>
				<view class="items_text" v-if="item.lastMessage">
					<view class="" v-if="!item.lastMessage.isRevoked">
						[{{ item.unreadCount == 0 ? '已读' : '未读' }}]
						<span v-if="item.lastMessage.type == 'TIMImageElem'">[图片]</span>
						<span v-if="item.lastMessage.type == 'TIMImageElem'">[图片]</span>
						<span v-if="item.lastMessage.type == 'TIMSoundElem'">[语音]</span>
						<span v-if="item.lastMessage.type == 'TIMVideoFileElem'">[视频]</span>
						<span v-if="item.lastMessage.type == 'TIMCustomElem'">[引用消息]</span>
						<span v-if="item.lastMessage.type == 'TIMTextElem'">
							{{ item.lastMessage.messageForShow }}
						</span>
					</view>
					<span v-if="item.lastMessage.isRevoked && userID == item.lastMessage.fromAccount">你撤回了一条消息</span>
					<span v-if="item.lastMessage.isRevoked && userID != item.lastMessage.fromAccount">对方撤回了一条消息</span>
				</view>
			</view>
		</view>
		<view class="kong" v-if="list.length == 0">
			<view class="text">暂无数据</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: [],
			current: 1,
			userID: uni.getStorageSync('userID')
		};
	},
	onShow() {
		let that = this;
		if (uni.getStorageSync('login')) {
			that.getlist();
		}
	},
	methods: {
		//获取会话列表
		getlist() {
			uni.$TUIKit.getConversationList().then((res) => {
				this.list = res.data.conversationList;
			});
		},
		golitian(item) {
			uni.navigateTo({
				url: `/chat/chat?conversationID=C2C${item.userProfile.userID}`
			});
		}
	}
};
</script>

<style lang="scss">
page {
	background: #fff;
}
.kong {
	image {
		width: 288rpx;
		height: 288rpx;
	}
	.text {
		margin-top: 20rpx;
	}
	text-align: center;
	font-family: PingFang SC, PingFang SC;
	font-weight: 500;
	font-size: 28rpx;
	color: #adaaaa;
	line-height: 33rpx;
	margin-top: 200rpx;
}
.item {
	padding: 30rpx;
	border-bottom: 1px solid #eee;
	box-sizing: border-box;
	display: flex;
	align-items: center;
	.img {
		width: 80rpx;
		height: 80rpx;
		border-radius: 10rpx;
		position: relative;

		.tip {
			position: absolute;
			right: -35rpx;
			top: -35rpx;
		}

		image {
			width: 80rpx;
			height: 80rpx;
			border-radius: 10rpx;
		}
	}

	.items_cont {
		flex: 1;
		margin-left: 20rpx;
		height: 80rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.items_top {
		display: flex;
		justify-content: space-between;
		align-items: center;

		.items_name {
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 28rpx;
			color: #000000;
			width: 400rpx;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}

		.items_time {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 24rpx;
			color: #adaaaa;
		}
	}

	.items_text {
		width: 580rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 28rpx;
		color: #adaaaa;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		display: flex;
		align-items: center;

		view {
			width: 580rpx;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}
	}

	.test {
		margin-left: 20rpx;
	}
}
</style>
